/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DoctorAndNurseViewUnmodifiable.java
 *
 * Created on Oct 23, 2011, 1:19:35 AM
 */
package pkg1;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.DefaultListModel;
import javax.swing.JFrame;

/**
 * Objects of this class represent views displaying the doctors 
 * and nurses currently on shift.
 * @author Nick
 */
public class DoctorAndNurseView extends javax.swing.JFrame {

    /** Creates new form DoctorAndNurseViewUnmodifiable */
    public DoctorAndNurseView() {
        this.setTitle("Doctor And Nurse View");
        context = Context.getContext();
        floorContext = context.getFloor("emergency room");
        initComponents();
    }

    /**
     * initializes the components of the GUI
     */
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jList1.addMouseListener(new DoctorMouseHandler());
        jScrollPane2 = new javax.swing.JScrollPane();
        jList2 = new javax.swing.JList();
        jList2.addMouseListener(new NurseMouseHandler());
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        doctorModel = new DefaultListModel();
        nurseModel = new DefaultListModel();

        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        this.setLocationRelativeTo(null);
        
        setUpDoctorModel();
        setUpNurseModel();
        
        jList1.setModel(doctorModel);
        jScrollPane1.setViewportView(jList1);

        jList2.setModel(nurseModel);
        jScrollPane2.setViewportView(jList2);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel1.setText("Doctors On Shift:");

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel2.setText("Nurses On Shift:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(44, 44, 44)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(50, 50, 50)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(50, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(49, 49, 49)
                        .addComponent(jLabel2)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 171, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap(52, Short.MAX_VALUE)
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(51, 51, 51))
        );

        pack();
    }// </editor-fold>
    
    /**
     * Sets up the Doctor List
     */
    private void setUpDoctorModel() {
        for(Doctor doctor : context.getDoctors()) {
            doctorModel.addElement(doctor);
        }
    }
    
    /**
     * Sets up the nurse's list
     */
    private void setUpNurseModel() {
        for(Nurse nurse: context.getNurses()) {
            nurseModel.addElement(nurse);
        }
    }
    
    /**
     * if a doctor is selected, pops up the view displaying that
     * doctors patients.
     */
    private class DoctorMouseHandler extends MouseAdapter {
      public void mouseClicked(MouseEvent event) {
         // add a new square if the cursor isn't inside a square
         if(jList1.getSelectedValues().length == 1) {
             PatientList list = new PatientList((Provider)jList1.getSelectedValue());
             list.setVisible(true);
         }
      }
    }

     /**
     * if a nurse is selected, pops up the view displaying that
     * nurses patients.
     */
    private class NurseMouseHandler extends MouseAdapter {
      public void mouseClicked(MouseEvent event) {
         // add a new square if the cursor isn't inside a square
         if(jList2.getSelectedValues().length == 1) {
             PatientList list = new PatientList((Provider)jList2.getSelectedValue());
             list.setVisible(true);
         }
      }
    }
    
    // Variables declaration - do not modify
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JList jList1;
    private javax.swing.JList jList2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private DefaultListModel doctorModel;
    private DefaultListModel nurseModel;
    private FloorContext floorContext;
    private Context context;
    // End of variables declaration
}
